var Bullet = {
	new:function(parentID){
		var bullet = $.extend(true,{},Bullet.template);
		// add properties
		bullet = Physics.addNeutonian(bullet);
		// add to game loop
		bullet = Dimension.addDimension(bullet);
		bullet.id = Game.getID();
		bullet.parentID = parentID;
		Game.bullets[bullet.id] = bullet;
		return Game.bullets[bullet.id];
	},
	template:{
		color:"rgb(255,255,255)",		
		width:2,			height:6,
		vMax:10,			vMin:0,
		accel:10,			decel:10,
		angleAccel:0,		angleAccelMax:0,
		lifespan:50,		life:0,
		onUpdate:function(){
			this.life++;
			var color = 255 - this.life * 6;
			this.color = 'rgb('+color+','+color+','+color+')';
			//console.log(this.color);
			if(this.life > this.lifespan){
				delete Game.bullets[this.id];
			}
			// check for collision
			for(var actorID in Game.actors){
				if(actorID != this.parentID){ // don't test against self
					if(
						this.x >= Game.actors[actorID].xMin && 
						this.x <= Game.actors[actorID].xMax &&
						this.y >= Game.actors[actorID].yMin &&
						this.y <= Game.actors[actorID].yMax
					){
						// level 2 collision detection
						for(var componentID in Game.actors[actorID].components){
							// calculate corners
							Game.actors[actorID].components[componentID] = Dimension.calculateCorners(Game.actors[actorID].components[componentID],true);
							// create the polygon
							// find the 4 points relative to initial
							var x2 = Game.actors[actorID].components[componentID].x1 - Game.actors[actorID].components[componentID].x2;
							var y2 = Game.actors[actorID].components[componentID].y1 - Game.actors[actorID].components[componentID].y2;
							var x3 = Game.actors[actorID].components[componentID].x1 - Game.actors[actorID].components[componentID].x3;
							var y3 = Game.actors[actorID].components[componentID].y1 - Game.actors[actorID].components[componentID].y3;
							var x4 = Game.actors[actorID].components[componentID].x1 - Game.actors[actorID].components[componentID].x4;
							var y4 = Game.actors[actorID].components[componentID].y1 - Game.actors[actorID].components[componentID].y4;
							//console.log(x2 + ' ' + y2 + ' ' + x3 + ' ' + y3 + ' ' + x4 + ' ' + y4);
							var polygon = new Game.P(
								new Game.V(Game.actors[actorID].components[componentID].x1,Game.actors[actorID].components[componentID].y1),
								[new Game.V(0,0),
									new Game.V(x2,y2),
									new Game.V(x3,y3),
									new Game.V(x4,y4)]
							);
							var point = new Game.V(this.x,this.y);
							console.log(point);
							console.log(polygon);
							if(SAT.pointInPolygon(point,polygon)){
								delete Game.bullets[this.id];
							}
						}
					}
				}
			}
		}
	}
};